<?php
require_once "../Common/values.php";
require_once "../Common/database.php";

switch($_GET[f])
{
case (it);
 $formaction='../index.php?f=helpdesk&p=hnew';
 break;
case (publicnew);
 $formaction='publicnew.php';
 break;
case (password);
 $formaction='passwordreset.php';
 break;
case (newuser);
 $formaction='newuser.php';
  break;
}
$attributes = array("givenname", "sn", "title", "pager", "mail" ,"telephonenumber", "department", "physicaldeliveryofficename");
# define filter
 $filter = '(sn=*'.$_POST[lastname].'*)';

    $ad = ldap_connect($ldapaddress)
          or die("Couldn't connect to AD!");
  
    ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);

    $bd = ldap_bind($ad,$ldapuser,$ldappwd)
          or die("Couldn't bind to AD!");

echo '<h2>Results</h2>';
echo '<table border=1 width=75%><tr bgcolor=#1DBAEF><td>Tel EXT:</td><td>Firstname</td><td>Lastname</td><td>Office</td><td>Department</td><td>Job Title</td><td>TEL. NUMBER
</td><td>Email</td></tr>';

 $query= mysql_query("SELECT * FROM tblldap");
 while($row = mysql_fetch_array($query))
     {
 #run this string on evey search
    $result = ldap_search($ad, $row[dn], $filter, $attributes);
    $entries = ldap_get_entries($ad, $result);

#table with results
    for ($i=0; $i<$entries["count"]; $i++)
    {
        echo '<form action="'.$formaction.'" method="POST"><tr><td><input type=Hidden name="phone" value="'.$entries[$i]["telephonenumber"][0].'">'.$entries[$i]["telephonenumber"][0].'</td><td><input type=hidden name=\"1name\" value="'.$entries[$i]["givenname"][0].'">'.$entries[$i]["givenname"][0].'</td><td>'.$entries[$i]["sn"][0].'</td><td><input type=hidden name="branch" value="'.$entries[$i]["physicaldeliveryofficename"][0].'">'.$entries[$i]["physicaldeliveryofficename"][0].'</td><td><input type=hidden name="department" value="'.$entries[$i]["department"][0].'">'.$entries[$i]["department"][0].'</td><td>'.$entries[$i]["title"][0].'</td><td>'.$entries[$i]["pager"][0].'</td><td>'.$entries[$i]["mail"][0].'</td><td><input type=submit value=Select></td><td><input type=hidden name="requestor" value="'.$entries[$i]["givenname"][0].' ',$entries[$i]["sn"][0].'"><input type=hidden name="mail" value="'.$entries[$i]["mail"][0].'"></TD></tr></form>';
    }


 
     }

echo '</table>';
if($_GET[f]!='newuser')
    {
echo '<br><a href="'.$formaction.'">Not on list ?</a>';
    }





ldap_unbind($ad);

?>

